package com.csd.action.teacher;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.csd.helper.ActionResult;
import com.csd.helper.IConstant;
import com.csd.helper.SessionManager;
import com.csd.pojo.Teacher;
import com.csd.service.ITeacherService;
import com.csd.vo.UserVO;

public  class TeacherInfoAction {
	
	private Teacher teacher ;
	private ITeacherService teacherService;

	public ITeacherService getTeacherService() {
		return teacherService;
	}

	public void setTeacherService(ITeacherService teacherService) {
		this.teacherService = teacherService;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}
    
	
	public String execute()
	{
		String result = ActionResult.fail;
		Integer teacherID = null;
		//获得teacherID
		try {
			HttpSession httpSession = ServletActionContext.getRequest().getSession();
			UserVO value = (UserVO)httpSession.getAttribute(IConstant.userVO);
			if(value == null){
				throw  new Exception("用户未登录异常");
			}
			//Integer id = value.getUserID();
			teacherID = value.getUserID();//SessionManager.getUserID(httpSession);
		} catch (Exception e) {
			System.out.println("TeacherInfoAction");
			e.printStackTrace();
		}
		
		if (teacherID != null) {
			 teacher = teacherService.getTeacherByID(teacherID);
			 result = ActionResult.success;
			 return result;
		}else {
			return  result;
		}
	
	}
	
}
